package com.lemon.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class PutExtraActivity extends AppCompatActivity {

    EditText editText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_put_extra);

        editText = findViewById(R.id.edit_zhen);

    }

    public void onToastButtonClicked(View v) {
        switch (v.getId()) {
            case R.id.button_put_extra_zhen:
                Intent intent = new Intent(PutExtraActivity.this,PutExtraSecondActivity.class);
                intent.putExtra("string",editText.getText().toString());
                startActivity(intent);
                break;
            case R.id.button_put_extra_fan:
                Intent intent2 = new Intent(PutExtraActivity.this,PutExtraSecondActivity.class);
                startActivityForResult(intent2,1);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case 1:
                if (resultCode  == RESULT_OK) {
                    String fan = data.getStringExtra("fan");
                    editText.setText(fan);
                    break;
                }
        }
    }
}
